import { createElement } from 'react'
import { withI18n } from '@lingui/react'
import { Upload, message, Modal } from 'antd'

const Unite = (page, id) => {
  // page  1 支持全部设备
  //       2 单一设备
  //       3 其他
  let operation_type = sessionStorage.getItem('operation_type')
  let em_id = sessionStorage.getItem('em_id')
  if (page == 2 && operation_type == 1 && em_id == 'all') {
    Modal.error({
      title: '请选择需配置的具体设备!',
      width: '30%',
      content: '不能选择“所有被管理设备”,只能选择需要进行配置的具体设备',
    })
    return false
  } else if ((page == 1 || page == 2) && operation_type == 1 && em_id == null) {
    Modal.error({
      title: '请选择设备!',
      width: '30%',
      content: '设备不能为空,请在设备选择处选择设备',
    })
    return false
  } else if (page == 3 && operation_type == 1 && em_id == null) {
    return false
  } else {
    return true
  }
}
const UniteAPi = (url) => {
  let em = [
    '/home/msg',
    '/em/get_usr_em',
    '/em/get_all',
    '/action?command=queryserialnum',
    '/em/test_em',
    '/em/add',
    '/em/del',
    '/em/get_one',
    'em/update',
    'action?command=querymailstatus',
    'bw/add_global',
    'bw/update_global',
    'bw/add_personal',
    'bw/update_personal',
    'refreshtoken',
  ]
  let bw = [
    'bw/add_global',
    'bw/update_global',
    'bw/add_personal',
    'bw/update_personal',
  ]
  let em_id = ''
  if (
    sessionStorage.getItem('em_id') != null &&
    sessionStorage.getItem('operation_type') == 1
  ) {
    if (url.indexOf('em_id') != -1) {
    } else {
      em_id = '&em_id=' + sessionStorage.getItem('em_id')
    }
  } else {
    em_id = ''
  }
  let event = em.every((item) => url.indexOf(item) === -1)
  if (event) {
    url = url + em_id
  } else {
    url = url
  }
  let bws = bw.every((item) => url.indexOf(item) === -1)
  if (!bws) {
    if (url.indexOf('em_id') != -1) {
    } else {
      url = url + '?em_id=' + sessionStorage.getItem('em_id')
    }
  }
  return url
}
export { Unite, UniteAPi }
